package com.code.user.client.hystrix;

import com.code.commons.model.Model;
import com.code.commons.model.qo.PageQO;
import com.code.commons.model.vo.PageVO;
import com.code.user.client.LoginCredentialClient;
import com.code.user.model.po.LoginCredential;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Collections;
import java.util.List;
import java.util.Set;

/**
 * 登陆凭证的熔断回调类
 *
 * @author tangyifei
 */
@Component
@Slf4j
public class LoginCredentialClientHystrix implements LoginCredentialClient {

    @Override
    public LoginCredential getLoginCredential(@RequestParam("account") String account, @RequestParam("type") String type) {
        log.info("获取单个登录凭证相关的信息发生请求超时，走熔断！");
        return LoginCredential.builder().build();
    }

    @Override
    public List<LoginCredential> getLoginCredentialList(@RequestParam("account") String account, @RequestParam("type") List<String> type) {
        log.info("获取多个登录凭证信息列表发生请求超时，走熔断！");
        return Collections.emptyList();
    }

    @Override
    public void modifyTranPwd(@RequestParam("id") Long id, @RequestParam("newTranPwd") String newTranPwd) {
        log.info("重置交易密码发生请求超时，走熔断！");
    }

    @Override
    public LoginCredential getUserLoginCredential(@RequestParam("userId") String userId) {
        log.info("通过用户主键获取用户登录凭证信息发生请求超时，走熔断！");
        return LoginCredential.builder().build();
    }

    @Override
    public LoginCredential add(@RequestBody LoginCredential loginCredential) {
        log.info("添加登录凭证信息发生请求超时，走熔断！");
        return LoginCredential.builder().build();
    }

    @Override
    public int deleteById(@PathVariable("id") Long id) {
        log.info("根据主键删除登录凭证信息发生请求超时，走熔断！");
        return 0;
    }

    @Override
    public LoginCredential updateByIdSelective(@PathVariable("id") Long id, @RequestBody LoginCredential record) {
        log.info("部分修改登录凭证信息发生请求超时，走熔断！");
        return LoginCredential.builder().build();
    }

    @Override
    public LoginCredential updateById(@PathVariable("id") Long id, @RequestBody LoginCredential record) {
        log.info("全部修改登录凭证信息发生请求超时，走熔断！");
        return LoginCredential.builder().build();
    }

    @Override
    public LoginCredential getById(@PathVariable("id") Long id) {
        log.info("根据主键获取登录凭证信息发生请求超时，走熔断！");
        return LoginCredential.builder().build();
    }

    @Override
    public List<LoginCredential> getByIds(@RequestBody Set<Long> ids) {
        log.info("根据多个主键获取多个登录凭证信息发生请求超时，走熔断！");
        return Collections.emptyList();
    }

    @Override
    public PageVO<LoginCredential> getPage(@RequestBody PageQO<? extends Model> pageQO) {
        log.info("分页查询登录凭证信息发生请求超时，走熔断！");
        return new PageVO<>();
    }

    @Override
    public String trace(@PathVariable("command") String cmd) {
        log.info("测试或诊断登录凭证信息发生请求超时，走熔断！");
        return "trace request timeout!";
    }
}
